

import 'package:get/get.dart';
import 'package:wechat_manager/common/constant.dart';
import 'package:wechat_manager/network/network_helper.dart';
import 'package:wechat_manager/utils/log_util.dart';
import 'package:wechat_manager/utils/preferences_util.dart';

class HomeController extends GetxController {


  @override
  Future<void> onReady() async {
    //getStableAccessToken();
    // String token  = await PreferencesUtil.getAccessToken();
    // logger.i(token);
  }

  void getStableAccessToken() {
    var params = {
      "grant_type" : "client_credential",
      "appid" : Constant.APP_ID,
      "secret" : Constant.APP_SECRET
    };
    NetworkHelper.INSTANCE.baseService.getAccessToken(params).then((res) {
      logger.i(res.toJson());
      if((res.accessToken ?? "").isNotEmpty) {
        PreferencesUtil.setAccessToken(res.accessToken ?? "");
      }
    });
  }
}